package com.dapeng.cleardatabackend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dapeng.cleardatabackend.common.BaseResponse;
import com.dapeng.cleardatabackend.common.ResultUtils;
import com.dapeng.cleardatabackend.model.dto.node.NodeAddRequest;
import com.dapeng.cleardatabackend.model.dto.node.NodeDeleteRequest;
import com.dapeng.cleardatabackend.model.dto.node.NodeGetRequest;
import com.dapeng.cleardatabackend.model.dto.node.NodeUpdateRequest;
import com.dapeng.cleardatabackend.model.vo.NodeVO;
import com.dapeng.cleardatabackend.service.NodeService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author dapeng
 * @description 图谱节点控制器
 * @date 2024/12/22 22:42
 */
@RestController
@RequestMapping("/node")
public class NodeController {

    @Resource
    private NodeService nodeService;

    /**
     * 获取节点列表
     *
     * @param nodeGetRequest 获取节点请求
     * @return {@link BaseResponse }<{@link Page }<{@link NodeVO }>>
     */
    @PostMapping("/page/original")
    public BaseResponse<Page<NodeVO>> getNodePage(@RequestBody @Valid NodeGetRequest nodeGetRequest) {
        Page<NodeVO> page = nodeService.getNodePage(nodeGetRequest);
        return ResultUtils.success(page);
    }


    /**
     * 创建节点
     *
     * @param nodeAddRequest 节点添加请求
     * @return {@link BaseResponse }<{@link Boolean }>
     */
    @PostMapping("/add")
    public BaseResponse<Long> addNode(@RequestBody @Valid NodeAddRequest nodeAddRequest) {
        return ResultUtils.success(nodeService.addNode(nodeAddRequest));
    }

    /**
     * 更新节点
     *
     * @param nodeUpdateRequest 节点更新请求
     * @return {@link BaseResponse }<{@link Boolean }>
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateNode(@RequestBody @Valid NodeUpdateRequest nodeUpdateRequest ) {
        return ResultUtils.success(nodeService.updateNode(nodeUpdateRequest));
    }

    /**
     * 删除节点
     *
     * @param nodeDeleteRequest 节点删除请求
     * @return {@link BaseResponse }<{@link Boolean }>
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteNode(@RequestBody @Valid NodeDeleteRequest nodeDeleteRequest) {
        return ResultUtils.success(nodeService.deleteNode(nodeDeleteRequest));
    }

    /**
     * 下载原始节点文件
     *
     * @param id id
     */
    @GetMapping("/download/original/{id}")
    public ResponseEntity<byte[]> downloadOriginal(@PathVariable("id") Long id) {
        return nodeService.downloadOriginalCsv(id);
    }
}
